window.onload=function (){

    function setNullToWu(a){
        if (a==null)
            return '无';
        else
            return a;
    }

    var passengerID=sessionStorage.getItem('userid');

    axios({
        method: 'get',
        url: '/StayRegisterController/selectMoneyBypassengerID/'+passengerID
    }).then(function (resp) {
        if (resp){
            var result=resp.data.data;
            //console.log(result);
            var tbody=document.getElementById("tbody");
            //循环添加节点，动态生成
            for (var i=0;i<result.length;i++){
                var td1=document.createElement("td");
                var td2=document.createElement("td");
                var td3=document.createElement("td");
                var td4=document.createElement("td");
                var td5=document.createElement("td");
                var td6=document.createElement("td");
                var td7=document.createElement("td");
                var td8=document.createElement("td");
                var td9=document.createElement("td");
                td1.innerHTML=i+1;
                td2.innerHTML=setNullToWu(result[i].consumptionId);
                td3.innerHTML=setNullToWu(result[i].id);
                td4.innerHTML=setNullToWu(result[i].roomID);
                td5.innerHTML=setNullToWu(result[i].roomStandardPriceDay);
                td6.innerHTML=setNullToWu(result[i].stayNumber);
                td7.innerHTML=setNullToWu(result[i].commodityName);
                td8.innerHTML=setNullToWu(result[i].consumptionMoney);
                td9.innerHTML=setNullToWu(result[i].consumptionTime);
                var tr=document.createElement('tr');
                tr.appendChild(td1);
                tr.appendChild(td2);
                tr.appendChild(td3);
                tr.appendChild(td4);
                tr.appendChild(td5);
                tr.appendChild(td6);
                tr.appendChild(td7);
                tr.appendChild(td8);
                tr.appendChild(td9);

                tbody.appendChild(tr);
                td6.style.borderRight='3px solid darkblue';
            }
            var allMoney=document.getElementById("allMoney");
            axios({
                method: 'get',
                url: '/StayRegisterController/getAllMoneyNum/'+passengerID
            }).then(function (resp) {
                allMoney.innerHTML=resp.data.data+'元';
            });
        }
        else {

        }
    });

    document.getElementById('cnt').onclick=function (){

    axios({
        method: 'get',
        url: '/StayRegisterController/getRoomsBypassengerID/'+passengerID
    }).then(function (resp) {
        var rooms=resp.data.data;
        for (var key in rooms){
            axios({
                method: 'put',
                url: '/RoomController/updateroomStatethree/'+key
            }).then(function (resp) {

            });
        }
        //完成修改room状态
        axios({
            method: 'put',
            url: '/StayRegisterController/changeStayRegistersIsBill/'+passengerID
        }).then(function (resp) {

        });
        alert('完成付款！');
        window.location.reload();
    });
    }
}